package com.cqw.controller;

import com.cqw.common.BaseResponse;
import com.cqw.domain.ImportUser;
import com.cqw.utils.ExcelUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-11-03 14:22
 * @Description:
 */
@RestController
@RequestMapping("/excel")
public class ExcelController {


    @GetMapping("/import")
    public BaseResponse importExcel(@RequestParam MultipartFile file) throws Exception {
        ExcelUtil<ImportUser> util = new ExcelUtil<>(ImportUser.class);
        List<ImportUser> importUsers = util.importExcel(file.getInputStream());
        for (ImportUser importUser : importUsers) {
            System.out.println(importUser);
        }
        return BaseResponse.success(importUsers);
    }


}
